package com.example.myapplicationndk.h264;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplicationndk.databinding.ActivityMainH264Binding;

// 录屏或者相机 生成H264 文件
public class MainH264Activity extends AppCompatActivity {


    ActivityMainH264Binding binding;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        binding = ActivityMainH264Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());


        checkPermission();
        binding.camera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("TAGG,", Thread.currentThread().getName());
            }
        });

        binding.screenStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ScreenShareEncode.init(MainH264Activity.this);
            }
        });

        binding.screenStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });



    }


    @RequiresApi(api = Build.VERSION_CODES.M)
    private void checkPermission() {
        requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA}, 101);


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == ScreenShareEncode.REQUEST_CODE && resultCode == Activity.RESULT_OK) {
            ScreenShareEncode.start(MainH264Activity.this, resultCode, data);
        }
    }

}